package com.capgemini.orf.security;

import java.nio.ByteBuffer;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public final class Account {
	private String email;
	private String hashedPassword;
	boolean active = true;

	public Account(String email, char[] password) {
		this.email = email;

		try {
			MessageDigest sha = MessageDigest.getInstance("SHA-512");

			byte[] passwordBytes = new byte[password.length];
			ByteBuffer.wrap(passwordBytes).asCharBuffer().put(password);

			sha.update(passwordBytes);
			hashedPassword = new String(sha.digest());
		} catch (NoSuchAlgorithmException e) {
			System.out.println("Dit algoritme wordt niet ondersteund...");
		} finally {
			for (int i = password.length - 1; i >= 0; i--) {
				password[i] = 0;
			}
		}
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getHashedPassword() {
		return hashedPassword;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}
}
